|
|
|
|
|
|
|
CreateLocalFile. Creates the database (MDB) file. |
|
|
|
|
|
|
|
|
CreateTable. Creates an empty table in the database. |
|
|
|
|
|
|
|
|
TransferTable. Transfers data from the SQL Server table to the new database. |
|
|
|
|
|
|
|
|
Main. Controls the flow of the program. |
|
|
|
|
|
|
|
|
These functions are shown in Listing 23.3. Following the listing is an explanation of what happens during a sample program run. |
|
|
|
|
|
|
|
|
Listing 23.3 SQLXPORT.ZIPTransferring Information from SQL to Access |
|
|
|
|
|
|
|
|
'Important variables:
Dim dbLocal As Database 'Destination database (Access)
Dim dbSQL As Database 'Source database (MS SQL Server)
Dim sDBLocalPath As String 'Path to destination database
Dim sINIPath As String 'Path to INI File
Sub Main()
Dim sConnect As String 'SQL Server Connect String
Dim nTables As Integer 'Number of tables to transfer
Dim nCurTable As Integer 'Counter for current table
Dim sSQLTable As String 'Name of the SQL table
Dim sMDBTable As String 'Name of the Access table
Dim sSection As String 'INI file [Section]
Dim nCommand As Integer 'Commands can be run on the
Dim sCommand As String 'Access database (i.e. create index)
'GET INI FILE NAME
sINIPath = App.Path & "\SQLXPORT.ini"
If Trim$(Command$) <> "" Then sINIPath = Command$
'READ INFO FROM THE INI FILE
sDBLocalPath = sGetINIString(sINIPath, "General", "DBFile", "test.mdb")
sConnect = sGetINIString(sINIPath, "General", "SQLConnect", "ODBC;")
nTables = CInt(sGetINIString(sINIPath, "Tables", "Tables", "0"))
'SHOW FORM AND CONNECT TO SQL SERVER
frmWait.Show
frmWait.lblWait = "Connecting to SQL Server . . ."
DoEvents
On Error GoTo MainError
Set dbSQL = OpenDatabase("", False, True, sConnect)
'CALL FUNCTION TO CREATE MDB FILE
frmWait.lblWait = "Creating MDB file . . ."
DoEvents
CreateLocalFile
DoEvents
'CREATE TABLES IN THE NEW MDB FILE
For nCurTable = 1 To nTables
sSQLTable = sGetINIString(sINIPath, "tables", "table" & nCurTable & _
"SQL", "none")
sMDBTable = sGetINIString(sINIPath, "tables", "table" & nCurTable & _ |
|
|
|
|
|